// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.core.process;

import java.util.ArrayList;
import java.util.List;

import org.dengues.core.components.IXMLComponent;
import org.dengues.core.components.NodePropertyParameter;
import org.dengues.core.external.IExternalData;
import org.dengues.core.metadata.MetadataTable;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-1-15 qiang.zhang $
 * 
 */
public abstract class AbstractCompNode implements ICompNode {

    private List<String> dataUniques = new ArrayList<String>();

    private List<String> trgOkUniques = new ArrayList<String>();

    protected IExternalData externalData;

    private List<NodePropertyParameter> elementParameters = new ArrayList<NodePropertyParameter>();

    private List<MetadataTable> metadataList = new ArrayList<MetadataTable>();

    private List<ICompConnection> incomingConnections = new ArrayList<ICompConnection>();

    private List<ICompConnection> outgoingConnections = new ArrayList<ICompConnection>();

    private IXMLComponent component;

    private String uniqueName;

    private String componentName;

    private boolean start;

    private boolean subProcessStart;

    private ICompProcess compProcess;

    public List<NodePropertyParameter> getElementParameters() {
        return elementParameters;
    }

    public void setElementParameters(List<NodePropertyParameter> elementParameters) {
        this.elementParameters = elementParameters;
    }

    public NodePropertyParameter getElementParameter(String name) {
        for (NodePropertyParameter parameter : elementParameters) {
            if (name.equals(parameter.getName())) {
                return parameter;
            }
        }
        return null;
    }

    public void setNodeParameterValue(String name, Object value) {
        NodePropertyParameter elementParameter = getElementParameter(name);
        if (elementParameter != null) {
            elementParameter.setValue(value);
        }
    }

    public List<MetadataTable> getMetadataList() {
        return this.metadataList;
    }

    public void setMetadataList(List<MetadataTable> metadataList) {
        this.metadataList = metadataList;
    }

    public List<ICompConnection> getIncomingConnections() {
        return this.incomingConnections;
    }

    public void addIncomingConnections(ICompConnection incomingConnection) {
        incomingConnections.add(incomingConnection);
    }

    public void removeIncomingConnections(ICompConnection incomingConnection) {
        incomingConnections.remove(incomingConnection);
    }

    public List<ICompConnection> getOutgoingConnections() {
        return this.outgoingConnections;
    }

    public void addOutgoingConnections(ICompConnection outgoingConnection) {
        this.outgoingConnections.add(outgoingConnection);
    }

    public void removeOutgoingConnections(ICompConnection outgoingConnection) {
        this.outgoingConnections.remove(outgoingConnection);
    }

    /**
     * Getter for uniqueName.
     * 
     * @return the uniqueName
     */
    public String getUniqueName() {
        return this.uniqueName;
    }

    /**
     * Sets the uniqueName.
     * 
     * @param uniqueName the uniqueName to set
     */
    public void setUniqueName(String uniqueName) {
        this.uniqueName = uniqueName;
    }

    /**
     * Getter for componentName.
     * 
     * @return the componentName
     */
    public String getCompName() {
        return this.componentName;
    }

    /**
     * Sets the componentName.
     * 
     * @param componentName the componentName to set
     */
    public void setComponentName(String componentName) {
        this.componentName = componentName;
    }

    /**
     * Getter for start.
     * 
     * @return the start
     */
    public boolean isStart() {
        return this.start;
    }

    /**
     * Sets the start.
     * 
     * @param start the start to set
     */
    public void setStart(boolean start) {
        this.start = start;
    }

    /**
     * Getter for subProcessStart.
     * 
     * @return the subProcessStart
     */
    public boolean isSubProcessStart() {
        return this.subProcessStart;
    }

    /**
     * Sets the subProcessStart.
     * 
     * @param subProcessStart the subProcessStart to set
     */
    public void setSubProcessStart(boolean subProcessStart) {
        this.subProcessStart = subProcessStart;
    }

    /**
     * Getter for component.
     * 
     * @return the component
     */
    public IXMLComponent getComponent() {
        return this.component;
    }

    /**
     * Sets the component.
     * 
     * @param component the component to set
     */
    public void setComponent(IXMLComponent component) {
        this.component = component;
    }

    /**
     * Getter for compProcess.
     * 
     * @return the compProcess
     */
    public ICompProcess getCompProcess() {
        return this.compProcess;
    }

    /**
     * Sets the compProcess.
     * 
     * @param compProcess the compProcess to set
     */
    public void setCompProcess(ICompProcess compProcess) {
        this.compProcess = compProcess;
    }

    /**
     * Sets the incomingConnections.
     * 
     * @param incomingConnections the incomingConnections to set
     */
    public void setIncomingConnections(List<ICompConnection> incomingConnections) {
        this.incomingConnections = incomingConnections;
    }

    /**
     * Sets the outgoingConnections.
     * 
     * @param outgoingConnections the outgoingConnections to set
     */
    public void setOutgoingConnections(List<ICompConnection> outgoingConnections) {
        this.outgoingConnections = outgoingConnections;
    }

    /**
     * Getter for externalData.
     * 
     * @return the externalData
     */
    public IExternalData getExternalData() {
        return this.externalData;
    }

    /**
     * Sets the externalData.
     * 
     * @param externalData the externalData to set
     */
    public void setExternalData(IExternalData externalData) {
        this.externalData = externalData;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        String s = getUniqueName();
        s = s + " : inputs["; //$NON-NLS-1$
        for (ICompConnection conn : getIncomingConnections()) {
            s = s + conn.getName() + ","; //$NON-NLS-1$
        }
        s = s + "]; outputs["; //$NON-NLS-1$
        for (ICompConnection conn : getOutgoingConnections()) {
            s = s + conn.getName() + ","; //$NON-NLS-1$
        }
        s = s + "]"; //$NON-NLS-1$
        return s;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#getDataUniques()
     */
    public List<String> getDataUniques() {
        return dataUniques;
    }

    /**
     * Getter for trgOkUniques.
     * 
     * @return the trgOkUniques
     */
    public List<String> getTrgOkUniques() {
        return this.trgOkUniques;
    }
}
